#include "stdafx.h"
#include "Collider.h"
#include "Entity.h"
#include "Enemy.h"
#include "TargetMediator.h"

bool SphereCollider::Intersects(Collider* collider){
	switch (collider->GetType()){
	case COLLIDER_BOX:
		return static_cast<BoxCollider*>(collider)->GetBoundingBox().Intersects(m_bounding_sphere);
		break;
	case COLLIDER_SPHERE:
		return static_cast<SphereCollider*>(collider)->GetBoundingSphere().Intersects(m_bounding_sphere);
		break;
	default:
		break;
	}
	return false;
}

bool BoxCollider::Intersects(Collider* collider){
	switch (collider->GetType()){
	case COLLIDER_BOX:
		return static_cast<BoxCollider*>(collider)->GetBoundingBox().Intersects(m_bounding_box);
		break;
	case COLLIDER_SPHERE:
		return static_cast<SphereCollider*>(collider)->GetBoundingSphere().Intersects(m_bounding_box);
		break;
	default:
		break;
	}
	return false;
}

void ScanCollider::Update(const Vector3& position, Entity* target){
	SphereCollider::Update(position);
	if (target != nullptr){
		if (!target->GetCollider()->Intersects(this)){
			Enemy* enemy = static_cast<Enemy*>(target);
			enemy->GetTargetMediator()->RemoveTarget(enemy);
		}
	}
}